"""
微信控制电脑命令号
@date 2019/10/27
@author hujing
"""
import itchat
from tool.command import Command


def command_response(line):
    itchat.send_msg(line, toUserName='filehelper')


command = Command(response_call=command_response, error_call=command_response)


@itchat.msg_register(itchat.content.TEXT, isGroupChat=False, isMpChat=False)
def dispose_command(msg):
    """
    处理微信发来的命令
    :param msg
    :return:
    """
    # 只接受文件传输助手的消息
    if msg['ToUserName'] != 'filehelper':
        return
    # 只处理文本消息
    if msg['Type'] != 'Text':
        return
    # 运行命令
    command.exec_command(str(msg['Text']))


if __name__ == '__main__':
    itchat.auto_login(hotReload=True, enableCmdQR=False)
    itchat.run()
